<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class CommissionRatio
 * Desc  城市抽成比例控制器
 * Create on 2024/11/8 17:13
 * Create by wangyafang
 */

namespace app\admin\controller\wddj\operationt;


use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;

class CommissionRatio extends Backend
{
    protected $model = null;
    protected $modelValidate = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\wddj\operationt\CommissionRatio();
    }

    /**
     * 抽成比例
     */
    public function index($city_id = null)
    {
        $row = $this->model->where('city_id',$city_id)->find();
        $this->assign(array(
            'city_id'=>$city_id,
            'row'=>$row,
        ));
        $this->assignconfig(array(
            'city_id'=>$city_id,
        ));
        if ($this->request->isPost()) {
            if (empty($row)) {
                $params = $this->request->post('row/a');
                if (empty($params)) {
                    $this->error(__('Parameter %s can not be empty', ''));
                }
                $params = $this->preExcludeFields($params);

                if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
                    $params[$this->dataLimitField] = $this->auth->id;
                }
                $result = false;
                Db::startTrans();
                try {
                    //是否采用模型验证
                    if ($this->modelValidate) {
                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
                        $this->model->validateFailException()->validate($validate);
                    }
                    $result = $this->model->allowField(true)->save($params);
                    Db::commit();
                } catch (ValidateException|PDOException|Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
                if ($result === false) {
                    $this->error(__('No rows were inserted'));
                }
            } else {
                $params = $this->request->post('row/a');
                if (empty($params)) {
                    $this->error(__('Parameter %s can not be empty', ''));
                }
                $params = $this->preExcludeFields($params);
                $result = false;
                Db::startTrans();
                try {
                    //是否采用模型验证
                    if ($this->modelValidate) {
                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                        $row->validateFailException()->validate($validate);
                    }
                    $result = $row->allowField(true)->save($params);
                    Db::commit();
                } catch (ValidateException|PDOException|Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
                if (false === $result) {
                    $this->error(__('No rows were updated'));
                }
            }

            $this->success('操作成功！');
        }
        return $this->view->fetch();
    }





    public function add()
    {
        return;
    }

    public function multi($ids = null)
    {
        return;
    }

    public function del($ids = null)
    {
        return;
    }

    public function edit($ids = null)
    {
        return;
    }


}



 